package com.hj.controller;



import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

import javax.jws.WebParam.Mode;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.junit.experimental.theories.suppliers.TestedOn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hj.Tools.MD5;
import com.hj.domain.Courseinfo;
import com.hj.domain.Studentinfo;
import com.hj.exception.CustomException;
import com.hj.service.inter.CourseServiceInter;
import com.hj.service.inter.StudentServiceInter;

//对数据库courseinfo表的操作
@Controller
@RequestMapping(value="/Course")
public class CourseController {
	
	@Autowired
	private CourseServiceInter courseServiceInter;
	
	//查询所有课程信息
	@RequestMapping("/queryAllCourse")
	public String queryAllCourse(Model model)throws Exception{
		 List<Courseinfo> list=courseServiceInter.queryAllCourse();
		 model.addAttribute("allCourses", list);
		 //查询成功
		 return "";
	}
	
	//模糊查询课程信息
	@RequestMapping("/searchCourseByTitle")
	public String searchCourseByTitle(Model model,String title)throws Exception{
		 List<Courseinfo> list=courseServiceInter.searchCourseByTitle(title);
		 model.addAttribute("allCourses", list);
		 //查询成功
		 return "";
	}
	//添加课程
	@RequestMapping("/insertCourse")
	public String insertCourse(String title,String desc,String totalStu,
			String hour,String startTime,String endTime,String type,String tag,String image )throws Exception{    
		Courseinfo courseinfo=new Courseinfo();
		courseinfo.setCosid(UUID.randomUUID().toString());
		courseinfo.setTitle(title);
		courseinfo.setDesc(desc);
		courseinfo.setTotalstu(totalStu);
		courseinfo.setHour(hour);
		courseinfo.setStarttime(startTime);
		courseinfo.setEndtime(endTime);
		courseinfo.setType(type);
		courseinfo.setTag(tag);
		courseinfo.setImage(image);
		courseServiceInter.insertCourse(courseinfo);
		//课程添加成功
		return "";
		
	}
	//更新课程
	@RequestMapping(value="/updatetCourse",method=RequestMethod.POST)
	public String updatetCourse(String cosId,String title,String desc,String totalStu,
			String hour,String startTime,String endTime,String type,String tag,String image,Model model)throws Exception{
		 
		Courseinfo courseinfo=new Courseinfo();
		courseinfo.setCosid(cosId);
		courseinfo.setTitle(title);
		courseinfo.setDesc(desc);
		courseinfo.setTotalstu(totalStu);
		courseinfo.setHour(hour);
		courseinfo.setStarttime(startTime);
		courseinfo.setEndtime(endTime);
		courseinfo.setType(type);
		courseinfo.setTag(tag);
		courseinfo.setImage(image);
		courseServiceInter.updateCourse(courseinfo);
		//课程信息修改成功
		return "";		
	}
	
	
}
